package com.thinkingstar.iads.projectcenter.entity.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.formula.functions.T;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Criteria;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import com.thinkingstar.iads.common.serviceImpl.EntityRepositoryServiceImpl;
import com.thinkingstar.iads.projectcenter.entity.PcProjectConstantData;
import com.thinkingstar.iads.projectcenter.entity.PcProjectEquipmentEquip;


/**
 * @ClassName: DaoPcEquipmentEquip 
 * @Description:项目中心_项目_设备配备维护
 * @author lyx
 * @date 2018年5月24日
 */
@IocBean(args = {"refer:dao"})
public class DaoPcEquipmentEquip extends EntityRepositoryServiceImpl<PcProjectEquipmentEquip>{

	public DaoPcEquipmentEquip(Dao dao) {
		super(dao);
	}
	
	//根据项目id查询设备配备
	public List <PcProjectEquipmentEquip> findEquipmentEquipByProjectId(String project_id){
		Criteria criteria = Cnd.NEW();
		criteria.where().and("del_flag", "=", false).and("project_id", "=", project_id);
		return query(criteria);
	}

	//根据项目id和设备配备表名称 查询设备配备
	public PcProjectEquipmentEquip findEquipmentEquipByProjectIdAndName(String project_id,String equipment_equip_name){
		Criteria criteria = Cnd.NEW();
		criteria.where().and("del_flag", "=", false).and("project_id", "=", project_id).and("equipment_equip_name","like","%"+equipment_equip_name+"%");
		List <PcProjectEquipmentEquip> list = query(criteria);
		if (null!=list &&list.size()>0) {
			return list.get(0);
		} else {
			return null;
		}
	}
	
	//code==>obj
	public PcProjectEquipmentEquip findObjByCode(String project_id , String code){
		Criteria criteria = Cnd.NEW();
		criteria.where().and("del_flag", "=", false).and("project_id", "=", project_id)
		.and("equipment_equip_code", "=", code);
		List <PcProjectEquipmentEquip> list = query(criteria);
 		if(list != null){
			return list.get(0);
		}
		return null;
	}
	
	public QueryResult findEquipmentEquipList(NutMap param){
		QueryResult queryResult = null;
		List <PcProjectEquipmentEquip> list = new ArrayList<>();
		Pager pager = null;
		Criteria criteria = Cnd.NEW();
		criteria.where().and("del_flag", "=", false);
		if(param.getString("project_id") != null){
			criteria.where().and("project_id", "=", param.getString("project_id"));
		}
		if(param.getString("equipment_equip_code") != null){
			criteria.where().and("equipment_equip_code", "=", param.getString("equipment_equip_code"));
		}
		if(param.getString("searchName") != null){
			criteria.where().and("equipment_equip_name", "like", "%"+param.getString("searchName")+"%");
		}
		criteria.getOrderBy().desc("create_time");
		if(param.get("page_num") != null && param.get("page_size") != null){
			pager = new Pager(param.getInt("page_num"), param.getInt("page_size"));
			pager.setRecordCount(count(criteria));
			list = query(criteria,pager);
		}else{
			list = query(criteria);
		}
		return new QueryResult(list,pager);
	}
	

}
